package com.nmh.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nmh.entity.Enclosure;
import com.nmh.entity.EnclosureAndPasture;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yoki
 * @since 2023-12-19
 */
@Repository
@Mapper
public interface EnclosureMapper extends BaseMapper<Enclosure> {
    @Select("SELECT p.pasture_name,e.circle_name,e.inventory,e.state,e.id FROM enclosure e join pasture p on e.pasture_id=p.pasture_id")
    public List<EnclosureAndPasture> selectall();

    @Insert("insert into enclosure (circle_name, pasture_id, inventory,state) VALUE (#{circleName},#{pastureId},#{inventory},1 )")
    boolean insertone(Enclosure enclosure);
//    @Update("update enclosure set circle_name =#{circleName},inventory=#{inventory} where id=#{id} ")
//    @Update({"<script>"+"update enclosure"+"<set>"+"<if circle_name!=null and circle_name!=''>"+"circle_name=#{circleName}}"+
//    "</if>"+"<if inventory!=null and inventory!=''>"+"</if>"+"</set>"+"<where>"+"id=#{id}"+"</where>"+"</script>"})
//    boolean updateone(Enclosure enclosure);
    @Update("update enclosure set state=#{state} where id=#{id} ")
    boolean updateState(Enclosure enclosure);
    @Select("select * from enclosure where circle_name=#{circleName}")
    Enclosure selectByCircleName(Enclosure enclosure);
    List<EnclosureAndPasture> selectEByThree(EnclosureAndPasture enclosureAndPasture);
}
